import { RJSFSchema } from '@rjsf/utils';
import { Tips } from './input';
const continuitySchema = {
  type: 'number',
  oneOf: [
    {
      type: 'number',
      title: '空间点',
      const: 0,
    },
    {
      type: 'number',
      title: '硬点',
      const: 1,
    },
    {
      type: 'number',
      title: '焊点',
      const: 2,
    },
  ],
  default: 0,
} as RJSFSchema;
const setSchema = (item): RJSFSchema => ({
  type: 'object',
  properties: {
    ...item,
    pointType: {
      title: '点类型',
      ...continuitySchema,
    },
  },
});
// formData 参数
export const insert = {
  mouse: setSchema({
    param: {
      type: 'string',
      title: '选择线和面加点',
    },
  }),
  coordinate: setSchema({
    x: {
      type: 'number',
      title: 'X坐标',
      default: 0,
    },
    y: {
      type: 'number',
      title: 'Y坐标',
      default: 0,
    },
    z: {
      type: 'number',
      title: 'Z坐标',
      default: 0,
    },
  }),
  parametric: setSchema({
    param: {
      type: 'string',
      title: '请指定比例~(0-1)或距离(0-...)',
    },
  }),
};
// formData input 框提示
export const extraUiSchema = {
  mouse: {
    param: {
      'ui:field': Tips,
      'ui:placeholder': `选择线和面添加点`,
    },
  },
  coordinate: {
    pointType: {
      'ui:options': {
        disabled: true,
      },
    },
  },
  parametric: {
    param: {
      'ui:placeholder': `最大值`,
      'ui:autofocus': false,
      'ui:classNames': 'cmd-insert-point',
    },
  },
};
// 参数整理  传入后端的参数 --- 鼠标
export const mouseParam = (formData) => {
  if (formData?.entityId) {
    return {
      target: formData?.entityId ? [formData.entityId] : [],
      source: formData.point,
      mode: 'coordinate',
      ptType: formData.pointType,
    };
  }
  return null;
};
// 参数整理  传入后端的参数 --- 坐标
export const coordinateParam = (formData) => {
  if (formData.x != null && formData.y != null && formData.z != null) {
    const param = {
      target: [],
      mode: 'coordinate',
      source: [formData.x || 0, formData.y || 0, formData.z || 0],
      ptType: formData.pointType,
    };
    return param;
  }
  return null;
};
// 参数整理  传入后端的参数 --- 参数化
export const parametricParam = (formData) => {
  if (formData.param && formData.entityId) {
    const param = {
      target: [formData.entityId],
      mode: 'length',
      ptType: formData.pointType,
      param: [parseFloat(formData.param)],
    };
    return param;
  }
  return null;
};
